package com.zmn.oms.dubbo.impl.zmn.shop.order;

import org.apache.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.oms.dubbo.dto.zmn.order.QuotationLogDIO;
import com.zmn.oms.dubbo.interfaces.zmn.shop.order.QuotationLogModifyRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.entity.log.OrderQuotationLog;
import com.zmn.oms.business.interfaces.log.OrderQuotationLogBService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;

/**
 * @author sunlife
 * @date:2021/1/8 7:20 下午
 * description:
 */
@Service(loadbalance = "roundrobin", timeout = 10000, retries = 2, version = DubboConsts.INTERFACE_VERSION, validation = "false")
public class QuotationLogModifyRemoteServiceImpl implements QuotationLogModifyRemoteService {

    private Logger logger = LoggerFactory.getLogger(QuotationLogModifyRemoteServiceImpl.class);

    @Autowired
    private OrderQuotationLogBService orderQuotationLogBService;

    @Override
    public ResponseDTO add(@Valid QuotationLogDIO dio) {
        try {
            logger.info("添加报价开始日志[{}] 入参：{}", dio.getOrderId(), JSON.toJSONString(dio));
            OrderQuotationLog log = BeanMapper.map(dio, OrderQuotationLog.class);
            log.setType(OrderConsts.QUOTATION_START);
            orderQuotationLogBService.saveLogWithOrderLog(log);
            return ResponseDTO.success();
        } catch (Exception e) {
            logger.error("添加报价日志失败：入参：{}, message:{} e:{}", JSON.toJSONString(dio), e.getMessage(), e);
            return ResponseDTO.fail("添加失败");
        }
    }
}
